package com.ruoyi.web.controller.fantasy;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyBankAccount;
import com.ruoyi.fantasy.service.IFantasyBankAccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 银行账户Controller
 * 
 * @author wanghui
 * @date 2020-06-18
 */
@Controller
@RequestMapping("/fantasy/fantasyBankAccount")
public class FantasyBankAccountController extends BaseController
{
    private String prefix = "fantasy/fantasyBankAccount";

    @Autowired
    private IFantasyBankAccountService fantasyBankAccountService;

    @RequiresPermissions("fantasy:fantasyBankAccount:view")
    @GetMapping()
    public String account()
    {
        return prefix + "/fantasyBankAccount";
    }

    /**
     * 查询银行账户列表
     */
    @RequiresPermissions("fantasy:fantasyBankAccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyBankAccount fantasyBankAccount)
    {
        startPage();
        List<FantasyBankAccount> list = fantasyBankAccountService.selectFantasyBankAccountList(fantasyBankAccount);
        return getDataTable(list);
    }

    /**
     * 导出银行账户列表
     */
    @RequiresPermissions("fantasy:fantasyBankAccount:export")
    @Log(title = "银行账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyBankAccount fantasyBankAccount)
    {
        List<FantasyBankAccount> list = fantasyBankAccountService.selectFantasyBankAccountList(fantasyBankAccount);
        ExcelUtil<FantasyBankAccount> util = new ExcelUtil<FantasyBankAccount>(FantasyBankAccount.class);
        return util.exportExcel(list, "account");
    }

    /**
     * 新增银行账户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存银行账户
     */
    @RequiresPermissions("fantasy:fantasyBankAccount:add")
    @Log(title = "银行账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyBankAccount fantasyBankAccount)
    {
        fantasyBankAccount.setId(String.valueOf(IdWorker.nextId()));
        fantasyBankAccount.setCreateTime(new Date());
        fantasyBankAccount.setUpdateTime(new Date());
        return toAjax(fantasyBankAccountService.insertFantasyBankAccount(fantasyBankAccount));
    }

    /**
     * 修改银行账户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyBankAccount fantasyBankAccount = fantasyBankAccountService.selectFantasyBankAccountById(id);
        mmap.put("fantasyBankAccount", fantasyBankAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存银行账户
     */
    @RequiresPermissions("fantasy:fantasyBankAccount:edit")
    @Log(title = "银行账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyBankAccount fantasyBankAccount)
    {
        fantasyBankAccount.setUpdateTime(new Date());
        return toAjax(fantasyBankAccountService.updateFantasyBankAccount(fantasyBankAccount));
    }

    /**
     * 删除银行账户
     */
    @RequiresPermissions("fantasy:fantasyBankAccount:remove")
    @Log(title = "银行账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyBankAccountService.deleteFantasyBankAccountByIds(ids));
    }
}
